package com.cps116.friendstracker;

import com.easy.facebook.android.apicall.FQL;
import com.easy.facebook.android.apicall.GraphApi;
import com.easy.facebook.android.facebook.Facebook;

import android.app.Application;
import android.util.Log;

public class FriendsTrackerApplication extends Application{

	private static final String TAG = FriendsTrackerApplication.class.getSimpleName();
	
	private Facebook facebook;
	private FQL facebookFQL;
	private GraphApi facebookGraph;
	private UserLocationUpdateService userLocationUpdateService;

	
	
	@Override
	public void onCreate() {
		super.onCreate();
		//create a user update service...
		userLocationUpdateService =  new UserLocationUpdateService();
	}


	@Override
	public void onTerminate() { // 
		super.onTerminate();
		Log.i(TAG, "onTerminated");
	}


	/*
	 * thread-safe accessing methods
	 */
	public synchronized Facebook getFacebook()
	{
		//not doing lazy instantiation...you have to be able to login in order to access facebook...
		//NOTE:** this has to be set up WHEN YOU LOG IN...
		return facebook;	
	}

	
	public synchronized FQL getFacebookFQL()
	{
		//lazy instantiation to save time
		if (facebookFQL == null)
			facebookFQL = new FQL(facebook);
		
		return facebookFQL;
	}
	
	
	public synchronized GraphApi getFacebookGraph()
	{
		//lazy instantiation to save time
		if (facebookGraph == null)
			facebookGraph = new GraphApi(facebook);
		
		return facebookGraph;
	}
	
	
	public void setFacebook(Facebook facebook) {
		Log.d("testing", String.format("facebook is setting: facebook" ));
		
		this.facebook = facebook;		
	}
	
	
	public UserLocationUpdateService getUserLocationUpdateService() {
		//lazy instantiation
		
		if (userLocationUpdateService == null)
			userLocationUpdateService = new UserLocationUpdateService();
		
		return userLocationUpdateService;
	}


	public void setUserLocationUpdateService(
			UserLocationUpdateService userLocationUpdateService) {
		this.userLocationUpdateService = userLocationUpdateService;
	}

	public void setUserLocationUpdateServiceInterval(float interval)
	{
		userLocationUpdateService.setUpdateTime(interval);
	}
	

}
